
var mysql = require("mysql");

var MianMysql;

//链接数据库(第一步)
exports.open_db=myopen;
function myopen(){
    MianMysql = mysql.createConnection({
        host:"localhost",
        user:"root",
        password:"",
        database:"mtour_db"
    })
}

exports.posttalk1 =function (req,res){
    var sql1= "select * FROM spot_info ; "
    MianMysql.query(sql1,function(error,data){
        if(error){
            console.log(error);
            res.end("系统错误");
        }else{
            console.log(data);
            res.send(data);
        }
    });
}
exports.posttalk2 =function (s1,res){
    var sql1= "select * FROM spot_info ,dest_d WHERE id_d=id_sInfo AND id_d=?;"
    MianMysql.query(sql1,[s1],function(error,data){
        if(error){
            console.log(error);
            res.end("系统错误");
        }else{
            console.log('hello');
            console.log(data);
            res.send(data);
        }
    });

}

//关闭数据库 (第三步)
exports.end_db = myend;
function myend(){
    MianMysql.end();
}
